package leetcode.L17;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class Solution1 {
    List<String> res = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        if (digits == null || digits.length() == 0) {
            return res;
        }
        String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        backTracking(digits, numString, 0);
        return res;
    }

    StringBuilder sb = new StringBuilder();
    private void backTracking(String digits, String[] numsString, int index) {
        if (index == digits.length()) {
            res.add(new String(sb));
            return;
        }
        String currString = numsString[digits.charAt(index)-'0'];
        for (int i = 0; i < currString.length(); i++) {
            sb.append(currString.charAt(i));
            backTracking(digits,numsString,index+1);
            sb.deleteCharAt(sb.length() - 1);
        }

    }

}